package xiaolong.zhou.spring_demo.Home;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import xiaolong.zhou.spring_demo.Pojo.Register;
import xiaolong.zhou.spring_demo.Pojo.SendEmail;
import xiaolong.zhou.spring_demo.Service.UserRegister;
import xiaolong.zhou.spring_demo.Service.achieve.SendEmailCaptchaAchieve;
import xiaolong.zhou.spring_demo.Utils.Result;
import xiaolong.zhou.spring_demo.Service.achieve.Captcha;

import java.awt.*;
import java.io.IOException;
import java.util.Map;

@Controller
@RequestMapping("/home/register")
@Slf4j
@ResponseBody
public class RegisterController {
    @Autowired
    private SendEmailCaptchaAchieve sendEmailAchieve;

    @Autowired
    private UserRegister userRegister;

    @Autowired
    private Captcha captchaUtils;

    @PostMapping("/")//用户注册
    public Result register(@RequestBody Register register) {
        return userRegister.register(register);
    }

    @GetMapping("/send_email")//注册发送邮箱验证码
    public Result sendEmail(@RequestBody SendEmail sendEmail) {
        return sendEmailAchieve.send(sendEmail);
    }

    @GetMapping ("/captcha")//注册获取图形验证码
    public Result captcha() throws IOException, FontFormatException {
        Map<String, Object> cap = captchaUtils.createCode();
        return Result.success(cap);
    }
}
